const router = require('koa-router')()
const { getWebAccessToken, getCustomer, sendCodeAction, addQuestionAction, wechatTelAction } = require('../servers/index');

router.prefix('/api')

//获取小程序的openid
router.post('/code', async (ctx, next) => {
  const { code } = ctx.request.body
  console.log('code===',code);
  console.log(ctx.request.body);
  const data = await getWebAccessToken(code);
  ctx.body = data;
})


//验证客户代码是正确性
router.post('/customer', async (ctx, next) => {
  const { customer } = ctx.request.body
  const data = await getCustomer(customer);
  ctx.body = data;
})


//发送短信验证码
router.get('/sendCode', async (ctx, next) => {
  const data = ctx.request.query;
  const result = await sendCodeAction(data);
  ctx.body = result;
})

//问答结果提交（客户代码，手机号，问答结果，地理位置信息
router.post('/addQuestion', async (ctx, next) => {
  const result = await addQuestionAction(ctx);
  ctx.body = result;
})

//验证短信验证码
router.post('/wechatTel', async (ctx, next) => {
  const result = await wechatTelAction(ctx);
  ctx.body = result;
})


module.exports = router
